<?php
class ThuchanhsController extends AppController {

	var $name = 'Thuchanhs';
	var $helpers = array('Html', 'Form');

	function index() {
		$this->Thuchanh->recursive = 0;
		$this->set('thuchanhs', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid Thuchanh', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('thuchanh', $this->Thuchanh->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Thuchanh->create();
			if ($this->Thuchanh->save($this->data)) {
				$this->Session->setFlash(__('The Thuchanh has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The Thuchanh could not be saved. Please, try again.', true));
			}
		}
		$tuans = $this->Thuchanh->Tuan->find('list');
		$nhomths = $this->Thuchanh->Nhomth->find('list');
		$phongs = $this->Thuchanh->Phong->find('list');
		$this->set(compact('tuans', 'nhomths', 'phongs'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Thuchanh', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Thuchanh->save($this->data)) {
				$this->Session->setFlash(__('The Thuchanh has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The Thuchanh could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Thuchanh->read(null, $id);
		}
		$tuans = $this->Thuchanh->Tuan->find('list');
		$nhomths = $this->Thuchanh->Nhomth->find('list');
		$phongs = $this->Thuchanh->Phong->find('list');
		$this->set(compact('tuans','nhomths','phongs'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Thuchanh', true));
			$this->redirect(array('action' => 'index'));
		}
		if ($this->Thuchanh->del($id)) {
			$this->Session->setFlash(__('Thuchanh deleted', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('The Thuchanh could not be deleted. Please, try again.', true));
		$this->redirect(array('action' => 'index'));
	}

}
?>